using System.Threading;
using UnityEngine;

namespace Assets.Scripts.GDK
{
	public class gdk_thread
	{
		private static gdk_thread _instance;

		private object obj = new object();

		private int num;

		public static gdk_thread Instance
		{
			get
			{
				if (_instance == null)
				{
					_instance = new gdk_thread();
				}
				return _instance;
			}
			set
			{
				_instance = value;
			}
		}

		private gdk_thread()
		{
			Thread thread = new Thread(Th_test1);
			Thread thread2 = new Thread(Th_test2);
			Thread thread3 = new Thread(Th_test3);
			thread.Start();
			thread2.Start();
			thread3.Start();
			thread.Priority = System.Threading.ThreadPriority.Highest;
			thread2.Priority = System.Threading.ThreadPriority.Normal;
			thread3.Priority = System.Threading.ThreadPriority.Lowest;
		}

		public void Th_lockTest()
		{
			UnityEngine.Debug.Log("测试多线程");
			while (true)
			{
				lock (obj)
				{
					num++;
					UnityEngine.Debug.Log(Thread.CurrentThread.Name + "测试多线程" + num);
				}
				Thread.Sleep(100);
				if (num > 300)
				{
					Thread.CurrentThread.Abort();
				}
			}
		}

		public void Th_test1()
		{
			for (int i = 0; i < 500; i++)
			{
				UnityEngine.Debug.Log("测试多线程1执行的次数:" + i);
				if (i > 200)
				{
					Thread.CurrentThread.Abort();
				}
			}
		}

		public void Th_test2()
		{
			for (int i = 0; i < 500; i++)
			{
				UnityEngine.Debug.Log("测试多线程2执行的次数:" + i);
				if (i > 300)
				{
					Thread.CurrentThread.Abort();
				}
			}
		}

		public void Th_test3()
		{
			for (int i = 0; i < 500; i++)
			{
				UnityEngine.Debug.Log("测试多线程3执行的次数:" + i);
				if (i > 400)
				{
					Thread.CurrentThread.Abort();
				}
			}
		}
	}
}
